//
//  SDMeTableViewController.m
//  GSD_WeiXin(wechat)
//
/*
 *********************************************************************************
 * QQ交流群: 459274049
 * Email : gsdios@126.com
 * GitHub: https://github.com/gsdios/GSD_WeiXin
 * 新浪微博:GSD_iOS
 *
 * 此“高仿微信”用到了很高效方便的自动布局库SDAutoLayout（一行代码搞定自动布局）
 * SDAutoLayout地址：https://github.com/gsdios/SDAutoLayout
 * SDAutoLayout视频教程：http://www.letv.com/ptv/vplay/24038772.html
 * SDAutoLayout用法示例：https://github.com/gsdios/SDAutoLayout/blob/master/README.md
 *
 *********************************************************************************
 
 */

#import "SDMeTableViewController.h"
#import "SD_ContactListVC.h"

@interface SDMeTableViewController ()
 
@property (weak, nonatomic) IBOutlet UITextField *registerMobileField;
@property (weak, nonatomic) IBOutlet UITextField *registerSecretField;
@property (weak, nonatomic) IBOutlet UITextField *registerVaileryField;

/** 登录 textField Mobile*/
@property (weak, nonatomic) IBOutlet UITextField *loginMobileField;

@property (weak, nonatomic) IBOutlet UITextField *loginSecretFiled;
@property (weak, nonatomic) IBOutlet UITextField *getMobieViaryField;

@end

@implementation SDMeTableViewController

-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    
    if (self==[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
         
    }  
    return [[UIStoryboard storyboardWithName:@"SDMeTableViewController" bundle:[NSBundle mainBundle]] instantiateInitialViewController];
    
} 

- (void)viewDidLoad {
    [super viewDidLoad];

    if ([[NSUserDefaults standardUserDefaults]objectForKey:@"user_token"]!=nil) {

    }

}
- (IBAction)veryButtonClick:(id)sender {
    
    
    NSMutableDictionary *dictM=[NSMutableDictionary dictionary];
    
    dictM[@"MobilePhone"]=self.getMobieViaryField.text; 
    
    AFHTTPSessionManager *manger=[AFHTTPSessionManager manager];
    manger.responseSerializer=[AFCompoundResponseSerializer serializer];
    
    [HYBNetworking postWithUrl:[NSString stringWithFormat:@"%@%@",host_api,very_api] refreshCache:YES params:dictM success:^(id response) {
        
        NSLog(@"==== %@",response);
    } fail:^(NSError *error) {
        
        NSLog(@" == %zd",error.code);
    }];
 
    
}


#pragma mark ===== 注册
- (IBAction)registerButtonClick:(id)sender {


    NSMutableDictionary *dictM=[NSMutableDictionary dictionary];

    dictM[@"MobilePhone"]=self.registerMobileField.text;
    dictM[@"Password"]=self.registerSecretField.text;
    dictM[@"PhoneVal"]=self.registerVaileryField.text;

 
    [HYBNetworking postWithUrl:[NSString stringWithFormat:@"%@%@",host_api,register_api] refreshCache:YES params:dictM success:^(id response) {
        
        NSLog(@"==== %@",response);
        
        
        [[NSUserDefaults standardUserDefaults]setObject:response[@"Token"] forKey:@"user_Id"];
        
        [[NSUserDefaults standardUserDefaults ]synchronize];



    } fail:^(NSError *error) {
        
        NSLog(@" == %zd",error.code);
    }];
}


#pragma mark ===== 登录
- (IBAction)loginButtonClick:(id)sender {


    NSMutableDictionary *dictM=[NSMutableDictionary dictionary];

    dictM[@"UserName"]=self.loginMobileField.text;
    dictM[@"Password"]=self.loginSecretFiled.text;

    NSLog(@" 手机:==%@..密码:==%@",self.loginMobileField.text,self.loginSecretFiled.text);

    NSLog(@"dictM==== %@",dictM);
    [HYBNetworking postWithUrl:[NSString stringWithFormat:@"%@%@",host_api,login_api] refreshCache:YES params:dictM success:^(id response) {
        
        NSLog(@"==== %@",response);
        if ([response[@"Status"] integerValue]==1) {
            [[NSUserDefaults standardUserDefaults]setObject:response[@"Token"] forKey:@"user_token"];
            [[NSUserDefaults standardUserDefaults]setObject:response[@"Message"] forKey:@"user_messageId"];
            [[NSUserDefaults standardUserDefaults ]synchronize];

            SD_ContactListVC *conList=[[SD_ContactListVC alloc]init];
            [self.navigationController pushViewController:conList animated:YES];
        }

        
    } fail:^(NSError *error) {
        
        NSLog(@" == %zd",error.code);
    }]; 


}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [self.view endEditing:YES];
}
@end
